Skip to content

Add backport GitHub Action #4228

Draft
dsmiley wants to merge 2 commits intoapache:mainfrom
dsmiley:copilot/add-backport-github-action
Draft

Add backport GitHub Action #4228
dsmiley wants to merge 2 commits intoapache:mainfrom
dsmiley:copilot/add-backport-github-action

Conversation

@dsmiley
Copy link
Contributor

@dsmiley dsmiley commented Mar 20, 2026

Adds automated PR backporting via sorenlouv/backport-github-action to streamline cherry-picking merged PRs onto maintenance branches.

Changes

  • .github/workflows/backport.yml — Workflow triggered on pull_request_target (labeled/closed). Runs only on merged PRs that don't carry the backport label (prevents re-backporting auto-created backport PRs). Requires contents: write and pull-requests: write permissions.

  • .backportrc.json — Configures available target branches and the label-to-branch mapping:

    {
      "targetBranchChoices": ["branch_10x", "branch_9x"],
      "branchLabelMapping": {
        "^backport-to-(.+)$": "$1"
      }
    }

Usage

Apply a label to a PR before or after merging:

Label Target branch
backport-to-branch_10x branch_10x
backport-to-branch_9x branch_9x

On merge, the action opens a new PR with the cherry-picked commit(s) against the target branch.

Copilot AI and others added 2 commits March 20, 2026 01:35
Co-authored-by: dsmiley <377295+dsmiley@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds automated backporting support to streamline cherry-picking merged PRs from main onto Solr maintenance branches via a GitHub Actions workflow plus repository backport configuration.

Changes:

  • Introduces a pull_request_target workflow to run the backport action on merged PRs when backport labels are present.
  • Adds .backportrc.json to define target branches and map backport-to-* labels to branch names.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
.github/workflows/backport.yml New workflow that triggers the backport action on merged PR events and prints action logs.
.backportrc.json New backport configuration defining eligible branches and label→branch mapping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pull-requests: write
steps:
- name: Backport Action
uses: sorenlouv/backport-github-action@v11
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workflow runs with contents: write / pull-requests: write on pull_request_target and invokes a third-party action by tag (sorenlouv/backport-github-action@v11). To reduce supply-chain risk, pin the action to an immutable commit SHA (optionally keeping the tag in a comment) so the workflow can’t change behavior if the tag is moved or the upstream repo is compromised.

Suggested change
uses: sorenlouv/backport-github-action@v11
uses: sorenlouv/backport-github-action@9d9e4d81a4c3f0a2d2c6b8a9e7f3c2b1d4f5a6b7 # v11

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +32
run: cat ~/.backport/backport.info.log

- name: Debug log
if: ${{ failure() }}
run: cat ~/.backport/backport.debug.log
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These log-printing steps will fail the job if the log files are not present (e.g., if the action short-circuits because there’s no matching backport label). Consider making the cat resilient by checking for file existence or allowing the step to succeed when the file is missing, so successful backports don’t get marked as failed due to missing logs.

Suggested change
run: cat ~/.backport/backport.info.log
- name: Debug log
if: ${{ failure() }}
run: cat ~/.backport/backport.debug.log
run: |
if [ -f "$HOME/.backport/backport.info.log" ]; then
cat "$HOME/.backport/backport.info.log"
else
echo "Info log not found at $HOME/.backport/backport.info.log"
fi
- name: Debug log
if: ${{ failure() }}
run: |
if [ -f "$HOME/.backport/backport.debug.log" ]; then
cat "$HOME/.backport/backport.debug.log"
else
echo "Debug log not found at $HOME/.backport/backport.debug.log"
fi

Copilot uses AI. Check for mistakes.
jobs:
backport:
name: Backport PR
if: github.repository == 'apache/solr' && github.event.pull_request.merged == true && !(contains(github.event.pull_request.labels.*.name, 'backport'))
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The job-level if: only checks merged and the absence of a literal backport label, so this workflow will run on any merged PR close/label event (including PRs merged into maintenance branches) even when no backport-to-* label is present. Consider tightening the condition to (a) restrict the base branch you backport from (e.g., github.event.pull_request.base.ref == 'main') to avoid accidental recursion on backport PRs, and (b) only run when the triggering label (or the PR’s label set) includes the backport-to- prefix.

Suggested change
if: github.repository == 'apache/solr' && github.event.pull_request.merged == true && !(contains(github.event.pull_request.labels.*.name, 'backport'))
if: github.repository == 'apache/solr' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' && contains(join(github.event.pull_request.labels.*.name, ' '), 'backport-to-')

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants